from django import template

register = template.Library()

@register.filter("hash")
def hash(dict,key):
  "Return the value of a key in a dictionary. "
  if(dict and dict.has_key(key)):
    return dict[key]
  else:
    return None

@register.filter("attr")
def attr(obj,key):
  "Return the value of a key in a obj. "
  if (obj):
    if(obj.hasattr(key)):
      return obj.getattr(key)
    else:
      return None
  else:
    return None
